package de.dfki.graph;

import de.dfki.graph.LabelEntry;
import de.dfki.graph.LabeledGraph;
import de.dfki.graph.LabeledVertex;
import de.dfki.graph.SimpleLabelnameOrder;
import de.dfki.graph.StringLabel;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * My personal priestess.
 * 
 * @author markus
 * 
 */
public class Phytia {

    static Random RANDOM = new Random();

    

    /**
     * Generates a random graph.
     * 
     * @param name
     * @return
     */
    public static LabeledGraph generateGraph(String name,
	    final int num_vertices, final int same_label) {
	int variance = (int) 10;
	int real_num = num_vertices - ((int) (RANDOM.nextDouble() * variance) * (RANDOM.nextBoolean() ? 1 : -1));
	List<LabelEntry> labels = new ArrayList<LabelEntry>();
	LabeledGraph graph = new LabeledGraph(name, new SimpleLabelnameOrder());
	
	for (int i = 0; i < ((real_num / same_label) + 1); i++) {
	    StringLabel label = new StringLabel("" + i);
	    labels.add(new LabelEntry(label));
	}
	for (int i = 0; i < real_num; i++) {
	    LabelEntry l = null;
	    while(true) {
		int pos = (int)(labels.size() * RANDOM.nextDouble());
		if(labels.size() == 0)
		    System.out.println(same_label + " : " + num_vertices);
		l = labels.get(pos);
		if(l.counter == same_label) {
		    labels.remove(pos);
		} else {
		    break;
		}
	    }
	    
	    LabeledVertex<StringLabel> v = graph.createVertex(""+i, l.label);
	    l.counter++;
	}

	return graph;

    }

}
